/**
 * @file bounds.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2024-03-30
 * 
 * @copyright Copyright (c) 2024
 * 
 */
#include "include/jsasm_config.h"

namespace base {

    template <typename T, typename U>
    inline constexpr bool IsInRange(T value, U lower_limit, U higher_limit) {
        // TODO DCHECK_LE(lower_limit, higher_limit);
        static_assert(sizeof(U) <= sizeof(T));
        using unsigned_T = typename std::make_unsigned<T>::type;

        // Use static_cast to support enum classes.
        return static_cast<unsigned_T>(static_cast<unsigned_T>(value) - static_cast<unsigned_T>(lower_limit)) <= 
            static_cast<unsigned_T>(static_cast<unsigned_T>(higher_limit) - static_cast<unsigned_T>(lower_limit));
    }

    template <typename T, typename = typename std::enable_if<std::is_unsigned<T>::value>::type>
    inline constexpr bool IsInBounds(T index, T length, T max) {
        return length <= max && index <= (max - length);
    }
} // namespace base